﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t101Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t101_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t101Mgr mgr = new t101Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t101(e.Parameters[t101_Filter.ParamPrefix]));
            IList<t101> list = mgr.FindAllByPage_t101(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t101_Filter.ParamPrefix]);
            t101_MainStore.DataSource = list;
            t101_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t101Mgr mgr = new t101Mgr();
            RowSelectionModel sm = t101_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t101 _t101 = new t101();
                _t101.t101_00 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t101(_t101))
                {
                    log.Debug("t101中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t101_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t101Mgr mgr = new t101Mgr();
            t101 _t101 = new t101();
            if (Hid.Text.Length > 0)
                _t101 = mgr.FindById_t101(int.Parse(Hid.Text));
            
			_t101.t101_01 = Txtt101_01.Text.Trim();
			_t101.t101_02 = Txtt101_02.Text.Trim();
			_t101.t101_03 = Txtt101_03.Text.Trim();
			_t101.t101_04 = Txtt101_04.Text.Trim();
			_t101.t101_05 = Txtt101_05.Text.Trim();
			_t101.t101_06 = Txtt101_06.Text.Trim();
			_t101.t101_07 = Txtt101_07.Text.Trim();
			_t101.t101_08 = Txtt101_08.Text.Trim();
			_t101.t101_70 = Txtt101_70.Text.Trim();
			_t101.t101_09 = Txtt101_09.Text.Trim();
			_t101.t101_10 = Txtt101_10.Text.Trim();
			_t101.t101_11 = Txtt101_11.Text.Trim();
			_t101.t101_71 = Txtt101_71.Text.Trim();
			_t101.t101_12 = Txtt101_12.Text.Trim();
			_t101.t101_13 = Txtt101_13.Text.Trim();
			_t101.t101_14 = Txtt101_14.Text.Trim();
			_t101.t101_15 = Txtt101_15.Text.Trim();
			_t101.t101_16 = Txtt101_16.Text.Trim();
			_t101.t101_17 = Txtt101_17.Text.Trim();
			_t101.t101_18 = Txtt101_18.Text.Trim();
			_t101.t101_19 = Txtt101_19.Text.Trim();
			_t101.t101_20 = Txtt101_20.Text.Trim();
			_t101.t101_21 = Txtt101_21.Text.Trim();
			_t101.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t101(_t101);
            else
                isok = mgr.Add_t101(_t101);
            if (isok)
            {
                t101_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t101中执行了保存（插入或修改），并成功");
                t101_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}